package com.gitee.wsl.coroutines.job.sheduler

import com.gitee.wsl.coroutines.job.JobDetail
import com.gitee.wsl.coroutines.job.JobKey
import com.gitee.wsl.coroutines.job.exception.SchedulerException
import com.gitee.wsl.coroutines.job.trigger.ITrigger
import com.gitee.wsl.coroutines.job.trigger.ITriggerListener
import com.gitee.wsl.coroutines.job.trigger.TriggerKey


/**
 * The interface to be implemented by classes that want to be informed of major
 * `[IScheduler]` events.
 *
 * @see IScheduler
 *
 * @see IJobListener
 *
 * @see ITriggerListener
 *
 * @author James House
 */
interface ISchedulerListener {
    /**
     * Called by the `[IScheduler]` when a
     * `[com.helger.quartz.IJobDetail]` is scheduled.
     *
     * @param trigger
     */
    fun jobScheduled(trigger: ITrigger) {}

    /**
     * Called by the `[IScheduler]` when a
     * `[com.helger.quartz.IJobDetail]` is unscheduled.
     *
     * @param triggerKey
     * @see ISchedulerListener.schedulingDataCleared
     */
    fun jobUnscheduled(triggerKey: TriggerKey) {}

    /**
     * Called by the `[IScheduler]` when a
     * `[ITrigger]` has reached the condition in which it will
     * never fire again.
     *
     * @param trigger
     */
    fun triggerFinalized(trigger: ITrigger) {}

    /**
     * Called by the `[IScheduler]` when a
     * `[ITrigger]` has been paused.
     *
     * @param triggerKey
     */
    fun triggerPaused(triggerKey: TriggerKey) {}

    /**
     * Called by the `[IScheduler]` when a group of
     * `[ITrigger]s` has been paused. If all groups were paused
     * then triggerGroup will be null.
     *
     * @param triggerGroup
     * the paused group, or null if all were paused
     */
    fun triggersPaused(triggerGroup: String) {}

    /**
     * Called by the `[IScheduler]` when a
     * `[ITrigger]` has been un-paused.
     *
     * @param triggerKey
     */
    fun triggerResumed(triggerKey: TriggerKey) {}

    /**
     * Called by the `[IScheduler]` when a group of
     * `[ITrigger]s` has been un-paused.
     *
     * @param triggerGroup
     */
    fun triggersResumed(triggerGroup: String) {}

    /**
     * Called by the `[IScheduler]` when a
     * `[com.helger.quartz.IJobDetail]` has been added.
     *
     * @param jobDetail
     */
    fun jobAdded(jobDetail: JobDetail) {}

    /**
     * Called by the `[IScheduler]` when a
     * `[com.helger.quartz.IJobDetail]` has been deleted.
     *
     * @param jobKey
     */
    fun jobDeleted(jobKey: JobKey) {}

    /**
     * Called by the `[IScheduler]` when a
     * `[com.helger.quartz.IJobDetail]` has been paused.
     *
     * @param jobKey
     */
    fun jobPaused(jobKey: JobKey) {}

    /**
     * Called by the `[IScheduler]` when a group of
     * `[com.helger.quartz.IJobDetail]s` has been paused.
     *
     * @param jobGroup
     * the paused group, or null if all were paused
     */
    fun jobsPaused(jobGroup: String) {}

    /**
     * Called by the `[IScheduler]` when a
     * `[com.helger.quartz.IJobDetail]` has been un-paused.
     *
     * @param jobKey
     */
    fun jobResumed(jobKey: JobKey) {}

    /**
     * Called by the `[IScheduler]` when a group of
     * `[com.helger.quartz.IJobDetail]s` has been un-paused.
     *
     * @param jobGroup
     */
    fun jobsResumed(jobGroup: String) {}

    /**
     *
     *
     * Called by the `[IScheduler]` when a serious error has
     * occurred within the scheduler - such as repeated failures in the
     * `JobStore`, or the inability to instantiate a `Job`
     * instance when its `Trigger` has fired.
     *
     *
     *
     * The `getErrorCode()` method of the given SchedulerException can
     * be used to determine more specific information about the type of error that
     * was encountered.
     *
     *
     * @param msg
     * @param cause
     */
    fun schedulerError(msg: String, cause: SchedulerException?) {}

    /**
     * Called by the `[IScheduler]` to inform the listener that
     * it has move to standby mode.
     */
    fun schedulerInStandbyMode() {}

    /**
     * Called by the `[IScheduler]` to inform the listener that
     * it has started.
     */
    fun schedulerStarted() {}

    /**
     * Called by the `[IScheduler]` to inform the listener that
     * it is starting.
     */
    fun schedulerStarting() {}

    /**
     * Called by the `[IScheduler]` to inform the listener that
     * it has shutdown.
     */
    fun schedulerShutdown() {}

    /**
     * Called by the `[IScheduler]` to inform the listener that
     * it has begun the shutdown sequence.
     */
    fun schedulerShuttingdown() {}

    /**
     * Called by the `[IScheduler]` to inform the listener that
     * all jobs, triggers and calendars were deleted.
     */
    fun schedulingDataCleared() {}
}
